package cn.chenhongchao.zhaobiaopingtai.service.impl;

import cn.chenhongchao.zhaobiaopingtai.entity.*;
import cn.chenhongchao.zhaobiaopingtai.mapper.PowerAccountRoleRelationMapper;
import cn.chenhongchao.zhaobiaopingtai.mapper.PowerRoleMapper;
import cn.chenhongchao.zhaobiaopingtai.service.IPowerAccountRoleRelationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
public class PowerAccountRoleRelationServiceImpl implements IPowerAccountRoleRelationService {
    @Resource
    private PowerAccountRoleRelationMapper powerAccountRoleRelationMapper;
    @Resource
    private PowerRoleMapper powerRoleMapper;

    @Override
    public  List<String> getByAccountId(Long id) {
        PowerAccountRoleRelationExample example = new PowerAccountRoleRelationExample();
        example.createCriteria()
                .andAccountIdEqualTo(id);
        List<PowerAccountRoleRelation> powerAccountRoleRelations = powerAccountRoleRelationMapper.selectByExample(example);
        List<String> stringList = new ArrayList<>();
        PowerRole powerRoles = new PowerRole();


        for (int i = 0; i < powerAccountRoleRelations.size(); i++) {
            PowerRoleExample example1 = new PowerRoleExample();
            example1.createCriteria().andIdEqualTo(powerAccountRoleRelations.get(i).getRoleId());
            powerRoles = powerRoleMapper.selectByExample(example1).get(0);
            if (powerRoles != null){
                stringList.add(i,powerRoles.getName());
            }
        }

        return stringList;
    }
}
